home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Tools & Apps / Graphics & Imaging / Ultra Dragging 1.0ß1 / UNothing.inc1.p < prev    next >
Encoding:
Text File  |  1991-04-02  |  20.3 KB  |  740 lines  |  [TEXT/MPS ]

  1. { UNothing.inc1.p}
  2. { Copyright © 1990, 1991 by Apple Computer, Inc. All rights reserved.}
  3.  
  4. {    Change List:
  5.  
  6.         ddmmyy
  7.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  8.                 error in TCGridView.DrawCell.
  9.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  10.                 error in TCIconTracker.CIconTrack>GetLocusFromScreen.
  11.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  12.                 error in TCIconTracker.CIconTrack>CopyToScreen.
  13.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  14.                 error in TComponentTracker.DoIt.
  15.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  16.                 error in TComponentTracker.UnDoIt.
  17.     GAP 070990    Eliminated unsafe use of an object field as a var or > 4 byte parameter
  18.                 error in TComponentTracker.ReDoIt.
  19.     GAP 081090    Changed TCIconTracker.ICIconTracker so the maxDepthGrafPort's portRect
  20.                 is the same as globRect and made sure the iconRect is within the bounds
  21.                 of the theMaxDevice^^.gdPMap^^.bounds.  Quickdraw was being finicky and
  22.                 would crash when these invariants were violated.
  23.     GAP 181290    Added more comments.
  24.     GAP 191290    Cleaned up formatting removed "GAP" comments.
  25.     GAP 191290    Added GetGrafEnv, SetOSGrafEnv, and SetGrafEnv calls in TCIconTracker.CIconTrack>>
  26.                 GetUnderNewIcon, so the graphics environment is properly set in the
  27.                 fUnderIcon OSImage.
  28. .    GAP 110191    Added sense parameter to PlaceComponent methods to indicate whether this
  29.                 is a placement (TRUE) or an undo of a placement (FALSE).
  30.     GAP 110190  TCGridView1.GetComponentTracker and TCGridView1.PlaceComponent
  31.                 are no longer overrides.
  32.     GAP 110191    Changed PlaceComponent methods from FUNCTIONS to PROCEDURES.
  33.     GAP    110191    Removed fOldComponentNumber instance variable from TComponentTracker
  34.                 and put it in TCGridView1.  Modified IComponentTracker, ICGridView,
  35.                 DoIt, UnDoIt, RedoIt, and PlaceComponent methods accordingly.
  36.                 PlaceComponent methods accordingly.
  37.     GAP    170191    Changed IComponentTracker to take a generic TView as its first argument
  38.                 as apposed to a TTrackingView.
  39.     GAP    170191    Changed TComponentTracker.TrackMouse>>NextView to take a generic TView as
  40.                 its first argument as apposed to a TTrackingView and also return a generic
  41.                 TView.
  42.     GAP    170191    Removed test for aView being a TTrackingView in TComponentTracker.TrackMouse>>
  43.                 NextView.
  44.     GAP    180191    Added TCGridView2 class.
  45.     GAP    180191    Removed argument from ICGridView1 and ICGridView2.
  46.     GAP    180191    Added TCGridView2 to gDeadStripSuppression clause in ICGridApplication.
  47.     GAP    180191    Altereed TCGridDocument.DoMakeViews so that the view created based on
  48.                 the gComponentPaletteFlag variable is either a TCGridView1 or a TCGridView2
  49.                 and not based on an argument passed to ICGridView1.
  50.     GAP    180191    Modified TComponentTrackerMethods to work on both TCGridView1 and TCGridView2
  51.                 views.
  52.     GAP    250191    Added a gApplication.InvalidateFocus to TComponentTracker.TrackMouse>>
  53.                 DesktopToLocal.  This prevents focus errors when passing over debugging
  54.                 windows/views.
  55.     GAP    250191    Removed references to, now obsolete, TOffscreenManager.Update.
  56.     GAP    250191    Added new data type, ComponentPlacementSense, that is now the type
  57.                 of the sense paramater in PlaceComponent.
  58.     GAP    280191    Added comments to TComponentTracker.TrackMouse and
  59.                 TComponentTracker.TrackMouse>>DesktopToLocal.
  60.     GAP    280191    Added clauses in TComponentTracker.TrackMouse>>NextView depending
  61.                 on whether gApplication.WMgrToWindow returns NIL or not.
  62.     GAP    310191    Added debugging code to TComponentTracker.DoIt.
  63.     GAP    010291    Added additional clause in TComponentTracker.TrackMouse>>NextView
  64.                 so that an existing view contains the mouse point it will still
  65.                 recursively try to find an appropriate subview.
  66.     GAP    010291    Added gApplication.Invalidate focus in TComponentTracker.TrackMouse>>
  67.                 DesktopToLocal before restoring desktopPort.
  68.     GAP    130291    Put freeing of fMaxDepthGrafPort in TCIconTracker.Free after
  69.                 FreeIfObject(fUnderIcon) because fUnderIcon may depend on fMaxDepthGrafPort.
  70.     GAP    190291    Changed TComponentTracker
  71.     GAP    190291    Changed TComponentTracker.TrackMouse>>NextView to fix bug where icon may
  72.                 be dropped on palette underneath, if it was the window previously tracking.
  73.                 Added fTrackingWindow instance variable to TComponentTracker and modified
  74.                 IComponentTracker and Fields methods accordingly.
  75.     GAP    190291    Changed TComponentTracker.TrackMouse>>NextView from a function to
  76.                 a procedure and eliminated the aTrackingView parameter.  NextView now
  77.                 modifies fTrackingView and fTrackingWindow through side-effects.
  78.     GAP    200291    Changed ClosePort to CloseCPort in TIconTracker.Free.
  79.     GAP    020491    Massive changes for latest version using UIconDragging unit.
  80.                 
  81.  
  82.  
  83.     End Change List. }
  84.  
  85.  
  86. { :::::::::::::::     TLooneyApplication     :::::::::::::::: }
  87.  
  88.  
  89. {$S AInit}
  90. PROCEDURE TLooneyApplication.ILooneyApplication (itsMainFileType: OSType);
  91.  
  92.     VAR
  93.         offscreenSize: Point;
  94.  
  95.     BEGIN {TLooneyApplication.ILooneyApplication}
  96.  
  97.         gLooneyPaletteFlag := TRUE;
  98.  
  99.         IApplication(itsMainFileType);
  100.  
  101.         IF gDeadStripSuppression THEN
  102.             BEGIN
  103.                 IF Member(TObject(NIL), TLooneyView1) THEN
  104.                 IF Member(TObject(NIL), TLooneyView2) THEN
  105.             END;
  106.  
  107.     END; {TLooneyApplication.ILooneyApplication}
  108.  
  109.  
  110. {$S AFields}
  111. PROCEDURE TLooneyApplication.Fields (PROCEDURE DoToField (fieldName: Str255;
  112.                                                           fieldAddr: Ptr;
  113.                                                           fieldType: INTEGER));
  114.     OVERRIDE;
  115.  
  116.     BEGIN {TLooneyApplication.Fields}
  117.         DoToField('TLooneyApplication', NIL, bClass);
  118.         DoToField('gLooneyApplication', @gLooneyApplication, bObject);
  119.         DoToField('gLooneyPaletteFlag', @gLooneyPaletteFlag, bBoolean);
  120.         INHERITED Fields(DoToField);
  121.     END;{TLooneyApplication.Fields}
  122.  
  123.  
  124. {$S AOpen}
  125. FUNCTION TLooneyApplication.DoMakeDocument (itsCmdNumber: cmdNumber): TDocument;
  126.     OVERRIDE;
  127.  
  128.     VAR
  129.         aLooneyDocument: TLooneyDocument;
  130.  
  131.     BEGIN {TLooneyApplication.DoMakeDocument}
  132.         NEW(aLooneyDocument);
  133.         FailNIL(aLooneyDocument);
  134.         aLooneyDocument.ILooneyDocument;
  135.         DoMakeDocument := aLooneyDocument;
  136.     END; {TLooneyApplication.DoMakeDocument}
  137.  
  138.  
  139. { :::::::::::::     TLooneyDocument      :::::::::::::: }
  140.  
  141.  
  142. {$S AOpen}
  143. PROCEDURE TLooneyDocument.ILooneyDocument;
  144.  
  145.     BEGIN {TLooneyDocument.ILooneyDocument}
  146.         IDocument(kFileType, kSignature, kUsesDataFork, NOT kUsesRsrcFork, NOT kDataOpen, NOT kRsrcOpen);
  147.     END; {TLooneyDocument.ILooneyDocument}
  148.  
  149.  
  150. {$S AFields}
  151. PROCEDURE TLooneyDocument.Fields (PROCEDURE DoToField (fieldName: Str255;
  152.                                                        fieldAddr: Ptr;
  153.                                                        fieldType: INTEGER));
  154.     OVERRIDE;
  155.  
  156.     BEGIN {TLooneyDocument.Fields}
  157.         DoToField('TLooneyDocument', NIL, bClass);
  158.         INHERITED Fields(DoToField);
  159.     END; {TLooneyDocument.Fields}
  160.  
  161.  
  162. {$S AOpen}
  163. PROCEDURE TLooneyDocument.DoMakeViews (forPrinting: BOOLEAN);
  164.     OVERRIDE;
  165.  
  166.     VAR
  167.         aWindow: TWindow;
  168.         aPrintHandler: TStdPrintHandler;
  169.         aLooneyView1: TLooneyView1;
  170.         aLooneyView2: TLooneyView2;
  171.  
  172.     BEGIN {TLooneyDocument.DoMakeViews}
  173.  
  174.         New(aPrintHandler);
  175.         FailNIL(aPrintHandler);
  176.         IF gLooneyPaletteFlag THEN
  177.             BEGIN
  178.                 aWindow := NewTemplateWindow(kLooneyWindow1ResID, SELF);
  179.                 aLooneyView1 := TLooneyView1(aWindow.FindSubView(kLooneyViewID));
  180.                 aLooneyView1.ILooneyView1;
  181.                 aPrintHandler.IStdPrintHandler(SELF,
  182.                                                aLooneyView1,
  183.                                                NOT kSquareDots,
  184.                                                NOT kFixedSize,
  185.                                                kFixedSize)
  186.             END
  187.         ELSE
  188.             BEGIN
  189.                 aWindow := NewTemplateWindow(kLooneyWindow2ResID, SELF);
  190.                 aLooneyView2 := TLooneyView2(aWindow.FindSubView(kLooneyViewID));
  191.                 aLooneyView2.ILooneyView2;
  192.                 aPrintHandler.IStdPrintHandler(SELF,
  193.                                                aLooneyView2,
  194.                                                NOT kSquareDots,
  195.                                                NOT kFixedSize,
  196.                                                kFixedSize)
  197.             END;
  198.             
  199.         gLooneyPaletteFlag := NOT gLooneyPaletteFlag;    { Alternate between the two palettes. }
  200.  
  201.     END; {TLooneyDocument.DoMakeViews}
  202.  
  203.  
  204. { ::::::::::::::     TLooneyView1     ::::::::::::::: }
  205.  
  206.  
  207. {$S AOpen}
  208. PROCEDURE TLooneyView1.ILooneyView1;
  209.  
  210.     VAR
  211.         i: INTEGER;
  212.  
  213.     BEGIN {TLooneyView1.ILooneyView1}
  214.  
  215.         fOldLooneyNumber := 0;
  216.         FOR i := 1 TO 10 DO
  217.             SELF.fLooneyNumbers[i] := 0;
  218.  
  219.     { Palette #1 }
  220.         fLooneyNumbers[1] := kDaffy1Icon;
  221.         fLooneyNumbers[2] := kBugsIcon;
  222.         fLooneyNumbers[3] := kSylvesterIcon;
  223.         fLooneyNumbers[4] := kTweetyIcon;
  224.         fLooneyNumbers[5] := kDaffy2Icon;
  225.         fLooneyNumbers[6] := kDevilIcon;
  226.         fLooneyNumbers[7] := kFogHornIcon;
  227.  
  228.     END; {TLooneyView1.ILooneyView1}
  229.  
  230.  
  231. {$S AFields}
  232. PROCEDURE TLooneyView1.Fields (PROCEDURE DoToField (fieldName: Str255;
  233.                                                     fieldAddr: Ptr;
  234.                                                     fieldType: INTEGER));
  235.  
  236.     VAR
  237.         i: INTEGER;
  238.         iString: Str255;
  239.  
  240.     BEGIN {TLooneyView1.Fields}
  241.         DoToField('TLooneyView1', NIL, bClass);
  242.         FOR i := 1 TO kMaxLooneys DO
  243.             BEGIN
  244.                 NumToString(i, iString);
  245.                 DoToField(CONCAT('fLooneyNumbers', iString, ']'), @fLooneyNumbers[i], bInteger);
  246.             END;
  247.         INHERITED Fields(DoToField);
  248.     END; {TLooneyView1.Fields}
  249.  
  250.  
  251. {$S ASelCommand}
  252. FUNCTION TLooneyView1.DoMouseCommand (VAR theMouse: Point;
  253.                                       VAR info: EventInfo;
  254.                                       VAR hysteresis: Point): TCommand;
  255.     OVERRIDE;
  256.  
  257.     VAR
  258.     
  259.         aVPoint: VPoint;
  260.         aCell: GridCell;
  261.         offset: Point;
  262.         aLooneyNumber: LooneyNumber;
  263.  
  264.     FUNCTION GetLooneyNumber (aCell: GridCell): INTEGER;
  265.  
  266.         VAR
  267.             aLooneyIndex: INTEGER;
  268.     
  269.         BEGIN {GetLooneyNumber}
  270.             aLooneyIndex := SELF.GetIndexFromCell(aCell);
  271.             GetLooneyNumber := fLooneyNumbers[aLooneyIndex];
  272.         END; {GetLooneyNumber}
  273.     
  274.     FUNCTION MouseDownOffset (aCell: GridCell): Point;
  275.  
  276.         VAR
  277.         
  278.             cellRect: VRect;
  279.             offset: Point;
  280.             width, height: LONGINT;
  281.     
  282.         BEGIN {MouseDownOffset}
  283.             SELF.CellToVRect(aCell, cellRect);
  284.             WITH cellRect DO
  285.                 BEGIN
  286.                     width := right - left;
  287.                     height := bottom - top;
  288.                     offset.h := (left + (width - kIconWidth) DIV 2) - aVPoint.h; { a negative value }
  289.                     offset.v := (top + (height - kIconHeight) DIV 2) - aVPoint.v; { a negative value }
  290.                 END;
  291.             MouseDownOffset := offset
  292.         END; {MouseDownOffset}
  293.     
  294.     BEGIN {TLooneyView1.DoMouseCommand}
  295.         DoMouseCommand := gNoChanges;
  296.         IF SELF.Focus THEN
  297.             BEGIN
  298.                 SELF.QDToViewPt(theMouse, aVPoint);
  299.                 aCell := SELF.VPointToCell(aVPoint);
  300.                 aLooneyNumber := GetLooneyNumber(aCell);
  301.                 offset := MouseDownOffset(aCell);
  302.                 DoMouseCommand := SELF.GetLooneyPlacer(aLooneyNumber, offset)
  303.             END
  304.     END; {TLooneyView1.DoMouseCommand}
  305.  
  306.  
  307. {$S ARes}
  308. PROCEDURE TLooneyView1.DrawCell (aCell: GridCell; aQDRect: Rect);
  309.  
  310.     VAR
  311.         bkgndColor, oldBkgndColor: RGBColor;
  312.  
  313.     BEGIN {TLooneyView1.DrawCell}
  314.         INHERITED DrawCell(aCell, aQDRect);        { Draw the relief surface }
  315.  
  316.         GetIfBkColor(oldBkgndColor);            { Draw the new stuff "on top", preserving the back color }
  317.         bkgndColor := fBkgndColor;
  318.         SetIfBkColor(bkgndColor);
  319.  
  320.         SELF.PlotMyIcon(aCell, aQDRect);
  321.         SELF.PlotMyText(aCell, aQDRect);
  322.  
  323.         SetIfBkColor(oldBkgndColor);
  324.     END; {TLooneyView1.DrawCell}
  325.  
  326.  
  327. {$S ARes}
  328. PROCEDURE TLooneyView1.PlotMyIcon (aCell: GridCell; aQDRect: Rect);
  329.  
  330. {    Plot the icon within a cell.    }
  331.  
  332.     VAR
  333.     
  334.         index: INTEGER;
  335.         theLooney: Looney;
  336.         theRect: Rect;
  337.         shrinkH, shrinkV: INTEGER;
  338.  
  339.     BEGIN {TLooneyView1.PlotMyIcon}
  340.         index := SELF.GetIndexFromCell(aCell);
  341.         IF fLooneyNumbers[index] <> 0 THEN
  342.             BEGIN
  343.                 theRect := aQDRect;
  344.                 shrinkH := (LengthRect(theRect, h) - kIconWidth) DIV 2;
  345.                 shrinkV := (LengthRect(theRect, v) - kIconHeight) DIV 2;
  346.                 InsetRect(theRect, shrinkH, shrinkV);
  347.  
  348.                 theLooney := GetCIcon(fLooneyNumbers[index]);
  349.                 PlotCIcon(theRect, theLooney);
  350.                 DisposCIcon(theLooney)
  351.             END
  352.     END; {TLooneyView1.PlotMyIcon}
  353.  
  354.  
  355. {$S ARes}
  356. PROCEDURE TLooneyView1.PlotMyText (aCell: GridCell; aQDRect: Rect);
  357.  
  358. {    Plot the text within a cell.    }
  359.  
  360.     BEGIN {TLooneyView1.PlotMyText}
  361.     END; {TLooneyView1.PlotMyText}
  362.  
  363.  
  364. {$S ARes}
  365. FUNCTION TLooneyView1.GetIndexFromCell (aCell: GridCell): INTEGER;
  366.  
  367. {    Calculate the index of a LooneyNumber from it's cell.    }
  368.  
  369.     BEGIN {TLooneyView1.GetIndexFromCell}
  370.         GetIndexFromCell := aCell.h + kNumberOfColumns * (aCell.v - 1);
  371.     END; {TLooneyView1.GetIndexFromCell}
  372.  
  373.  
  374. {$S ARes}
  375. FUNCTION TLooneyView1.GetLooneyPlacer (aLooneyNumber: LooneyNumber;
  376.                                        offset: Point): TLooneyPlacer;
  377.  
  378. {    Get a new Looney tracker for this view.    }
  379.  
  380.     VAR
  381.         aLooneyPlacer: TLooneyPlacer;
  382.  
  383.     BEGIN {TLooneyView1.GetLooneyPlacer}
  384.         NEW(aLooneyPlacer);
  385.         FailNIL(aLooneyPlacer);
  386.         aLooneyPlacer.ILooneyPlacer(SELF, offset, aLooneyNumber);
  387.         GetLooneyPlacer := aLooneyPlacer
  388.     END; {TLooneyView1.GetLooneyPlacer}
  389.  
  390.  
  391. {$S ARes}
  392. PROCEDURE TLooneyView1.PlaceLooney (aLooneyNumber: LooneyNumber;
  393.                                     aVPoint: VPoint;
  394.                                     sense: LooneyPlacementSense);
  395.  
  396. {    Place a Looney in the cell encompassed by aVPoint- in the cell's coordinate space.    }
  397.  
  398.     VAR
  399.         destCell: GridCell;
  400.         index: INTEGER;
  401.  
  402.     BEGIN {TLooneyView1.PlaceLooney}
  403.         IF SELF.Focus THEN
  404.             BEGIN
  405.                 destCell := SELF.VPointToCell(aVPoint);
  406.                 IF ((destCell.h < 1) |
  407.                     (destCell.h > kNumberOfColumns)) |
  408.                     ((destCell.v > kNumberOfRows) |
  409.                     (destCell.v > kNumberOfRows)) THEN
  410.                     ProgramBreak('Problem In Placing Looney')
  411.                 ELSE
  412.                     BEGIN
  413.                         index := SELF.GetIndexFromCell(destCell);
  414.                         CASE sense OF
  415.                             placeIt, rePlaceIt :
  416.                                 BEGIN
  417.                                     fOldLooneyNumber := fLooneyNumbers[index];
  418.                                     fLooneyNumbers[index] := aLooneyNumber
  419.                                 END;
  420.                             unPlaceIt:
  421.                                 fLooneyNumbers[index] := fOldLooneyNumber
  422.                         END; {CASE}
  423.                         SELF.InvalidateCell(destCell)
  424.                     END
  425.             END
  426.     END; {TLooneyView1.PlaceLooney}
  427.  
  428.  
  429. { ::::::::::::::     TLooneyView2     ::::::::::::::: }
  430.  
  431.  
  432. {$S AOpen}
  433. PROCEDURE TLooneyView2.ILooneyView2;
  434.  
  435.     VAR
  436.         i: INTEGER;
  437.  
  438.     BEGIN {TLooneyView2.ILooneyView2}
  439.  
  440.         fOldLooneyNumber := 0;
  441.         FOR i := 1 TO 10 DO
  442.             SELF.fLooneyNumbers[i] := 0;
  443.  
  444.     { Palette #2 }
  445.         fLooneyNumbers[1] := kOscarIcon;
  446.         fLooneyNumbers[2] := kHobbsIcon;
  447.         fLooneyNumbers[3] := kCalvinIcon;
  448.         fLooneyNumbers[4] := kYinYangIcon;
  449.         fLooneyNumbers[5] := kMoofIcon
  450.  
  451.     END; {TLooneyView2.ILooneyView2}
  452.  
  453.  
  454. {$S AFields}
  455. PROCEDURE TLooneyView2.Fields (PROCEDURE DoToField (fieldName: Str255;
  456.                                                     fieldAddr: Ptr;
  457.                                                     fieldType: INTEGER));
  458.  
  459.     VAR
  460.         i: INTEGER;
  461.         iString: Str255;
  462.  
  463.     BEGIN {TLooneyView2.Fields}
  464.         DoToField('TLooneyView2', NIL, bClass);
  465.         FOR i := 1 TO kMaxLooneys DO
  466.             BEGIN
  467.                 NumToString(i, iString);
  468.                 DoToField(CONCAT('fLooneyNumbers', iString, ']'), @fLooneyNumbers[i], bInteger);
  469.             END;
  470.         INHERITED Fields(DoToField);
  471.     END; {TLooneyView2.Fields}
  472.  
  473.  
  474. {$S ASelCommand}
  475. FUNCTION TLooneyView2.DoMouseCommand (VAR theMouse: Point;
  476.                                       VAR info: EventInfo;
  477.                                       VAR hysteresis: Point): TCommand;
  478.     OVERRIDE;
  479.  
  480.     VAR
  481.     
  482.         aVPoint: VPoint;
  483.         aCell: GridCell;
  484.         offset: Point;
  485.         aLooneyNumber: LooneyNumber;
  486.  
  487.     FUNCTION GetLooneyNumber (aCell: GridCell): INTEGER;
  488.  
  489.         VAR
  490.             aLooneyIndex: INTEGER;
  491.     
  492.         BEGIN {GetLooneyNumber}
  493.             aLooneyIndex := SELF.GetIndexFromCell(aCell);
  494.             GetLooneyNumber := fLooneyNumbers[aLooneyIndex];
  495.         END; {GetLooneyNumber}
  496.     
  497.     FUNCTION MouseDownOffset (aCell: GridCell): Point;
  498.  
  499.         VAR
  500.         
  501.             cellRect: VRect;
  502.             offset: Point;
  503.             width, height: LONGINT;
  504.     
  505.         BEGIN {MouseDownOffset}
  506.             SELF.CellToVRect(aCell, cellRect);
  507.             WITH cellRect DO
  508.                 BEGIN
  509.                     width := right - left;
  510.                     height := bottom - top;
  511.                     offset.h := (left + (width - kIconWidth) DIV 2) - aVPoint.h; { a negative value }
  512.                     offset.v := (top + (height - kIconHeight) DIV 2) - aVPoint.v; { a negative value }
  513.                 END;
  514.             MouseDownOffset := offset
  515.         END; {MouseDownOffset}
  516.     
  517.     BEGIN {TLooneyView2.DoMouseCommand}
  518.         DoMouseCommand := gNoChanges;
  519.         IF SELF.Focus THEN
  520.             BEGIN
  521.                 SELF.QDToViewPt(theMouse, aVPoint);
  522.                 aCell := SELF.VPointToCell(aVPoint);
  523.                 aLooneyNumber := GetLooneyNumber(aCell);
  524.                 offset := MouseDownOffset(aCell);
  525.                 DoMouseCommand := SELF.GetLooneyPlacer(aLooneyNumber, offset)
  526.             END
  527.     END; {TLooneyView2.DoMouseCommand}
  528.  
  529.  
  530. {$S ARes}
  531. PROCEDURE TLooneyView2.DrawCell (aCell: GridCell; aQDRect: Rect);
  532.  
  533.     VAR
  534.         bkgndColor, oldBkgndColor: RGBColor;
  535.  
  536.     BEGIN {TLooneyView2.DrawCell}
  537.         INHERITED DrawCell(aCell, aQDRect);        { Draw the relief surface }
  538.  
  539.         GetIfBkColor(oldBkgndColor);            { Draw the new stuff "on top", preserving the back color }
  540.         bkgndColor := fBkgndColor;
  541.         SetIfBkColor(bkgndColor);
  542.  
  543.         SELF.PlotMyIcon(aCell, aQDRect);
  544.         SELF.PlotMyText(aCell, aQDRect);
  545.  
  546.         SetIfBkColor(oldBkgndColor);
  547.     END; {TLooneyView2.DrawCell}
  548.  
  549.  
  550. {$S ARes}
  551. PROCEDURE TLooneyView2.PlotMyIcon (aCell: GridCell; aQDRect: Rect);
  552.  
  553. {    Plot the icon within a cell.    }
  554.  
  555.     VAR
  556.     
  557.         index: INTEGER;
  558.         theLooney: Looney;
  559.         theRect: Rect;
  560.         shrinkH, shrinkV: INTEGER;
  561.  
  562.     BEGIN {TLooneyView2.PlotMyIcon}
  563.         index := SELF.GetIndexFromCell(aCell);
  564.         IF fLooneyNumbers[index] <> 0 THEN
  565.             BEGIN
  566.                 theRect := aQDRect;
  567.                 shrinkH := (LengthRect(theRect, h) - kIconWidth) DIV 2;
  568.                 shrinkV := (LengthRect(theRect, v) - kIconHeight) DIV 2;
  569.                 InsetRect(theRect, shrinkH, shrinkV);
  570.  
  571.                 theLooney := GetCIcon(fLooneyNumbers[index]);
  572.                 PlotCIcon(theRect, theLooney);
  573.                 DisposCIcon(theLooney)
  574.             END
  575.     END; {TLooneyView2.PlotMyIcon}
  576.  
  577.  
  578. {$S ARes}
  579. PROCEDURE TLooneyView2.PlotMyText (aCell: GridCell; aQDRect: Rect);
  580.  
  581. {    Plot the text within a cell.    }
  582.  
  583.     BEGIN {TLooneyView2.PlotMyText}
  584.     END; {TLooneyView2.PlotMyText}
  585.  
  586.  
  587. {$S ARes}
  588. FUNCTION TLooneyView2.GetIndexFromCell (aCell: GridCell): INTEGER;
  589.  
  590. {    Calculate the index of a LooneyNumber from it's cell.    }
  591.  
  592.     BEGIN {TLooneyView2.GetIndexFromCell}
  593.         GetIndexFromCell := aCell.h + kNumberOfColumns * (aCell.v - 1);
  594.     END; {TLooneyView2.GetIndexFromCell}
  595.  
  596.  
  597. {$S ARes}
  598. FUNCTION TLooneyView2.GetLooneyPlacer (aLooneyNumber: LooneyNumber;
  599.                                        offset: Point): TLooneyPlacer;
  600.  
  601. {    Get a new Looney tracker for this view.    }
  602.  
  603.     VAR
  604.         aLooneyPlacer: TLooneyPlacer;
  605.  
  606.     BEGIN {TLooneyView2.GetLooneyPlacer}
  607.         NEW(aLooneyPlacer);
  608.         FailNIL(aLooneyPlacer);
  609.         aLooneyPlacer.ILooneyPlacer(SELF, offset, aLooneyNumber);
  610.         GetLooneyPlacer := aLooneyPlacer
  611.     END; {TLooneyView2.GetLooneyPlacer}
  612.  
  613.  
  614. {$S ARes}
  615. PROCEDURE TLooneyView2.PlaceLooney (aLooneyNumber: LooneyNumber;
  616.                                     aVPoint: VPoint;
  617.                                     sense: LooneyPlacementSense);
  618.  
  619. {    Place a Looney in the cell encompassed by aVPoint- in the cell's coordinate space.    }
  620.  
  621.     VAR
  622.         destCell: GridCell;
  623.         index: INTEGER;
  624.  
  625.     BEGIN {TLooneyView2.PlaceLooney}
  626.         IF SELF.Focus THEN
  627.             BEGIN
  628.                 destCell := SELF.VPointToCell(aVPoint);
  629.                 IF ((destCell.h < 1) | (destCell.h > kNumberOfColumns)) | ((destCell.v > kNumberOfRows) | (destCell.v > kNumberOfRows)) THEN
  630.                     ProgramBreak('Problem In Placing Looney')
  631.                 ELSE
  632.                     BEGIN
  633.                         index := SELF.GetIndexFromCell(destCell);
  634.                         CASE sense OF
  635.                             placeIt, rePlaceIt :
  636.                                 BEGIN
  637.                                     fOldLooneyNumber := fLooneyNumbers[index];
  638.                                     fLooneyNumbers[index] := aLooneyNumber
  639.                                 END;
  640.                             unPlaceIt:
  641.                                 fLooneyNumbers[index] := fOldLooneyNumber
  642.                         END; {CASE}
  643.                         SELF.InvalidateCell(destCell)
  644.                     END
  645.             END
  646.     END; {TLooneyView2.PlaceLooney}
  647.  
  648.  
  649. { :::::::::::::     TLooneyPlacer     ::::::::::::::: }
  650.  
  651.  
  652. {$S ASelCommand}
  653. PROCEDURE TLooneyPlacer.ILooneyPlacer (aTrackingView: TView;
  654.                                        offset: Point;
  655.                                        aLooneyNumber: LooneyNumber);
  656.  
  657.     
  658.     BEGIN {TLooneyPlacer.ILooneyPlacer}
  659.  
  660.         SELF.IPlaceByNumber(aTrackingView, offset, aLooneyNumber);
  661. {???        fViewConstrain := FALSE        ???}
  662.  
  663.     END; {TLooneyPlacer.ILooneyPlacer}
  664.  
  665.  
  666. {$S AFields}
  667. PROCEDURE TLooneyPlacer.Fields (PROCEDURE DoToField (fieldName: Str255;
  668.                                                      fieldAddr: Ptr;
  669.                                                      fieldType: INTEGER));
  670.     OVERRIDE;
  671.  
  672.     BEGIN {TLooneyPlacer.Fields}
  673.         DoToField('TLooneyPlacer', NIL, bClass);
  674.         INHERITED Fields(DoToField);
  675.     END; {TLooneyPlacer.Fields}
  676.  
  677.  
  678. {    Actions    }
  679.  
  680. {$S ADoCommand}
  681. PROCEDURE TLooneyPlacer.DoIt;
  682.     OVERRIDE;
  683.     
  684.     VAR
  685.         releasePoint : VPoint;
  686.  
  687.  
  688.     BEGIN {TLooneyPlacer.DoIt}
  689.  
  690.         INHERITED DoIt;
  691.         
  692.         releasePoint := fReleasePoint;
  693.         IF MEMBER(fTrackingView, TLooneyView1) THEN
  694.             TLooneyView1(fTrackingView).PlaceLooney(fIconNumber, releasePoint, PlaceIt)
  695.         ELSE IF MEMBER(fTrackingView, TLooneyView2) THEN
  696.             TLooneyView2(fTrackingView).PlaceLooney(fIconNumber, releasePoint, PlaceIt)
  697.  
  698.     END; {TLooneyPlacer.DoIt}
  699.  
  700.  
  701. {$S ADoCommand}
  702. PROCEDURE TLooneyPlacer.UndoIt;
  703.     OVERRIDE;
  704.  
  705.     VAR
  706.         releasePoint : VPoint;
  707.  
  708.     BEGIN {TLooneyPlacer.UndoIt}
  709.  
  710.         INHERITED UndoIt;
  711.         
  712.         releasePoint := fReleasePoint;
  713.         IF MEMBER(fTrackingView, TLooneyView1) THEN
  714.             TLooneyView1(fTrackingView).PlaceLooney(fIconNumber, releasePoint, UnPlaceIt)
  715.         ELSE IF MEMBER(fTrackingView, TLooneyView2) THEN
  716.             TLooneyView2(fTrackingView).PlaceLooney(fIconNumber, releasePoint, UnPlaceIt)
  717.  
  718.     END; {TLooneyPlacer.UndoIt}
  719.  
  720.  
  721. {$S ADoCommand}
  722. PROCEDURE TLooneyPlacer.RedoIt;
  723.     OVERRIDE;
  724.  
  725.     VAR
  726.         releasePoint : VPoint;
  727.  
  728.     BEGIN {TLooneyPlacer.RedoIt}
  729.  
  730.         INHERITED RedoIt;
  731.  
  732.         releasePoint := fReleasePoint;
  733.         IF MEMBER(fTrackingView, TLooneyView1) THEN
  734.             TLooneyView1(fTrackingView).PlaceLooney(fIconNumber, releasePoint, RePlaceIt)
  735.         ELSE IF MEMBER(fTrackingView, TLooneyView2) THEN
  736.             TLooneyView2(fTrackingView).PlaceLooney(fIconNumber, releasePoint, RePlaceIt)
  737.  
  738.     END; {TLooneyPlacer.RedoIt}
  739.  
  740.